package com.william.taskrobot.service;

import com.william.taskrobot.model.BussessCategoryInfo;
import com.william.taskrobot.model.SessionInfo;
import com.william.taskrobot.service.Rule.RegexRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * RuleService class
 *
 * @author william
 * @date 2021/1/14
 */
@Service
public class RuleService {
    @Autowired
    private RegexRuleService regexRuleService;
    /**
     * 判断是否命中规则
     * @param info
     * @param session
     * @return
     */
    public boolean check(BussessCategoryInfo info, SessionInfo session){
        //符合所有正则规则，则认为匹配成功
        for(String regex:info.getRegexs()){
            if(!regexRuleService.match(regex,session.getCurrentQuestion())){
                return false;
            }
        }
        return true;
    }
}
